package xhwl.hmo.mall.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import xhwl.hmo.mall.R;
import xhwl.hmo.mall.http.bean.resp.OrderDetailResp;
import xhwl.hmo.mall.utils.GlideCircleTransform;
import xhwl.hmo.mall.views.ForumPictureView;
import xhwl.pulltorefresh.adapter.BaseAdapter;
import xhwl.pulltorefresh.adapter.ViewHolder;

/**
 * 订单评价列表的adapter
 */
public class OrderCommentAdapter extends BaseAdapter<OrderDetailResp.COMMENTINFOBean> {
    private Context context;
    List<OrderDetailResp.COMMENTINFOBean> commentinfoBeenList;
    private TextView name;
    private TextView date;
    private TextView tv_forum_content;
    private ForumPictureView forumPicView;

    public OrderCommentAdapter(Context context, List<OrderDetailResp.COMMENTINFOBean> commentinfoBeenList) {
        super(context, R.layout.item_order_comment, commentinfoBeenList);
        this.context = context;
        this.commentinfoBeenList = commentinfoBeenList;

    }

    @Override
    public void convert(ViewHolder holder, OrderDetailResp.COMMENTINFOBean commentinfoBeen) {
        holder.setText(R.id.name, commentinfoBeen.getMEMBER_NAME());
        holder.setText(R.id.date, commentinfoBeen.getCOMMENT_DATE());
        holder.setText(R.id.tv_forum_content, commentinfoBeen.getCOMMENT_DESC());
        final ForumPictureView forumPicView = (ForumPictureView) holder.getView(R.id.forumPicView);
        final ImageView touxiang = (ImageView) holder.getView(R.id.touxiang);
        Glide.with(context)
                .load(commentinfoBeen.getMEMBER_PIC())
                .transform(new GlideCircleTransform(context))
                .into(touxiang);
        final RatingBar ratingBar = (RatingBar) holder.getView(R.id.ratingBar);
        forumPicView.setData(commentinfoBeen.getCOMMENT_PIC(), 5);
        if (null != commentinfoBeen.getCOMMENT_LEVEL() && "" != commentinfoBeen.getCOMMENT_LEVEL()) {
            ratingBar.setRating(Float.parseFloat(commentinfoBeen.getCOMMENT_LEVEL()) / 2);
            ratingBar.setEnabled(false);
        }
    }
}
